package routers

import (
    "github.com/beego/beego/v2/server/web"
    "volux/controllers"
    "volux/middleware"
)

func init() {
    // 首先注册全局中间件
    web.InsertFilter("/*", web.BeforeRouter, middleware.NewRequestLoggerMiddleware().DumpRequest)
    web.InsertFilter("/*", web.AfterExec, middleware.NewRequestLoggerMiddleware().DumpResponse)

    // 健康检查相关路由
    health := &controllers.GatewayController{}
    web.Router("/health", health, "*:Health")
    web.Router("/v1/health", health, "*:Health")
    web.Router("/v1/spdk/status", health, "*:Health")

    // 版本信息相关路由
    web.Router("/version", &controllers.GatewayController{}, "get:GetGatewayVersion")
    web.Router("/v1/version", &controllers.GatewayController{}, "get:GetGatewayVersion")
    web.Router("/v1/spdk/version", &controllers.GatewayController{}, "get:GetGatewayVersion")

    // Gateway相关路由
    web.Router("/v1/gateways", &controllers.GatewayController{}, "get:GetGateways;post:AddGateway")
    web.Router("/v1/gateways/:id", &controllers.GatewayController{}, "post:AddGateway")
    web.Router("/v1/gateways/:id/heartbeat", &controllers.GatewayController{}, "post:Heartbeat")

    // Bdev相关路由
    web.Router("/v1/bdevs", &controllers.BdevController{}, "get:GetBdevs;post:CreateBdev")
    web.Router("/v1/bdevs/:name", &controllers.BdevController{}, "delete:DeleteBdev")

    // 子系统相关路由
    web.Router("/v1/subsystems", &controllers.SubsystemController{}, "get:GetSubsystems;post:CreateSubsystem")
    web.Router("/v1/subsystems/:nqn", &controllers.SubsystemController{}, "get:GetSubsystem;put:UpdateSubsystem;delete:DeleteSubsystem")

    // 命名空间相关路由
    web.Router("/v1/subsystems/:nqn/namespaces", &controllers.NamespaceController{}, "get:GetNamespaces;post:AddNamespace")
    web.Router("/v1/subsystems/:nqn/namespaces/:nsid", &controllers.NamespaceController{}, "delete:DeleteNamespace")

    // 监听器相关路由
    web.Router("/v1/subsystems/:nqn/listeners", &controllers.ListenerController{}, "get:GetListeners;post:AddListener")
    web.Router("/v1/subsystems/:nqn/listeners/:address/:port", &controllers.ListenerController{}, "delete:DeleteListener")

    // 主机相关路由
    web.Router("/v1/subsystems/:nqn/hosts", &controllers.HostController{}, "get:GetHosts;post:AddHost")
    web.Router("/v1/subsystems/:nqn/hosts/:host_nqn", &controllers.HostController{}, "delete:DeleteHost")

    // Transport相关路由
    web.Router("/v1/transports", &controllers.TransportController{}, "get:GetTransports;post:CreateTransport")
    web.Router("/v1/transports/:type", &controllers.TransportController{}, "put:UpdateTransport")
}